home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / nfsrc21.zip / _WHEREIS.ASM next >
Assembly Source File  |  1991-08-15  |  24KB  |  535 lines

  1. ; File......: _WHEREIS.ASM
  2. ; Author....: Steve Larsen
  3. ; CIS ID....: 76370,1532
  4. ; Date......: $Date:   15 Aug 1991 23:08:08  $
  5. ; Revision..: $Revision:   1.1  $
  6. ; Log file..: $Logfile:   E:/nanfor/src/_whereis.asv  $
  7. ;
  8. ; This is an original work by K. Stephan Larsen and is placed in
  9. ; the public domain.
  10. ;
  11. ; Modification history:
  12. ; ---------------------
  13. ;
  14. ; $Log:   E:/nanfor/src/_whereis.asv  $
  15. ;  
  16. ;     Rev 1.1   15 Aug 1991 23:08:08   GLENN
  17. ;  Forest Belt proofread/edited/cleaned up doc
  18. ;  
  19. ;     Rev 1.0   07 Jun 1991 21:56:10   GLENN
  20. ;  Initial revision.
  21. ;
  22. ;
  23.  
  24. PUBLIC __ft_where, __ft_tree
  25.  
  26. EXTRN   __storc:far, __retni:far, __parinfo:far, __parclen:far
  27. EXTRN   __parc:far, __xfree:far, __xalloc:far
  28.  
  29. ;
  30. ; Create offsets to mvars and DTA buffering area.  The segment "DATASG"
  31. ;  is culled from the free pool, therefore goes away when these functions
  32. ;  are not active.  All mvar initialization must take place at
  33. ;  runtime, rather than compiletime.
  34. ;
  35. DATASG  SEGMENT  'DATA'
  36.  
  37. filename        db      13 dup(?), ?            ; passed filename
  38. olddrive        db      ?                       ; our current drive
  39. eop        dw    ?                       ; pointer to end-of-path string
  40. count           dw      ?                       ; current element
  41. is_array        dw      ?                       ; parm No., if array was passed
  42. a_count         db      ?                       ; array length
  43. dirname         db      4 dup(?)                ; '*.*' mask for directories
  44. dir_nest        db      ?                       ; directory level
  45. dta_ptr         db      ?                       ; pointer to current dir dta
  46. path            db      ?, 20 * 14 dup(?)       ; buffer for current path
  47. dta_buff        db      20 * 43 dup(?)          ; DTA for directories
  48. std_dta         db      128 DUP(?)              ; DTA for files
  49.  
  50. dta_file_offset equ     1Eh                     ; offset to filename within DTA
  51. dta_attr_offset equ     15h                     ; offset to file type within DTA
  52. dta_len         equ     43                      ; length of DTA that we're interested in
  53. segsize         equ     $ - filename            ; amount of free pool memory req'd
  54.  
  55. DATASG  ends
  56.  
  57. ; local vars go on stack, this is necessary since we cannot access data
  58. ;  within our data seg until it is allocated
  59.  
  60. oldsegloc       equ     <ss:[bp-02h]>           ; Clipper's DS
  61. newsegloc       equ     <ss:[bp-04h]>           ; our data area's Segment
  62. newoffset       equ     <ss:[bp-06h]>           ; our data area's Offset
  63. newsegment      equ     <ss:[bp-08h]>           ; after adjusting to the first
  64.                                                 ; paragraph within our data
  65.                                                 ; area, this is the "Segment"
  66.                                                 ; value of our data seg
  67.  
  68. _NANFOR segment word public 'CODE'
  69.         ASSUME CS:_NANFOR
  70.  
  71. __ft_where PROC    FAR
  72.         push    ds                      ; save Clipper's environment
  73.         push    es
  74.         push    di
  75.         push    si
  76.         push    bp
  77.         mov     bp, sp
  78.         sub     sp, 08h                 ; make room on stack for locals
  79.  
  80. w_1:    call    GetParms                ; fetch parms, set up our data seg
  81.         mov     ds, newsegloc           ; now point DS to our data seg
  82.         assume  ds:datasg
  83.         mov     ax, offset path         ; point to the current path (starts
  84.         inc     ax     
  85.         mov     eop, ax                 ; first EOP is 1 past "\"
  86.         call    HuntMDown               ; look for files in root directory
  87.  
  88. w_2:    call    FirstDir                ; find first subdirectory
  89.         jc      w_4                     ;  no subdir, set DTA back 1 dir lvl
  90.  
  91. w_3:    call    IsParent                ; found dir, check for DOS signature
  92.         jc      w_5                     ;  nope, go to next directory
  93.  
  94.         call    HuntMDown               ; OK, now look for files in directory
  95.  
  96. w_6:    call    UpDir                   ; move DTA up a level for subdirs
  97.         jmp     w_2                     ;  and do it all over again
  98.  
  99. w_4:    call    DownDir                 ; go back one level, look for another
  100. w_5:    call    NextDir                 ;   subdir. If CY returns set, no more
  101.         jc      w_4                     ;   subdirs, back up another level...
  102.         jmp     w_3                     ; subdir was found, continue
  103.  
  104. HuntMDown:                              ; requires EOP in BL, DTA set
  105.         call    FindFile                ;  set up to look for files
  106.                                         ;  DI points to EOP
  107.         call    FindFirst               ; find first matching file in dir
  108. h_1:    jc      h_3                     ; if not found, return to calling routine
  109.  
  110.         inc     count                   ; file was found, increment count
  111.  
  112.         mov     si, offset std_dta + dta_file_offset    ; and point SI to 
  113.                                         ; file's name within current DTA
  114.  
  115.         call    File2Path               ; add filename to end of current path
  116.         call    Save2Array              ; copy full path/filename to array
  117.  
  118. h_2:    call    FindNext                ; set up DOS to find next file/dir
  119.         jmp     h_1
  120.  
  121. h_3:    clc                             ; clear carry if set by parent dir
  122.         retn                            ; endp HuntMDown
  123.  
  124. FirstDir:                               ; locates first subdir in a level
  125.         call       FindDir              ; set up DOS search parms for a dir
  126.         call       MakePath             ; create the path
  127.         mov        si, offset dirname   ; add the "*.*" to the path
  128.         call       File2Path
  129.         mov        cx, 10h              ; directory attribute to search for
  130.         call       FindFirst            ; go do it
  131.         retn
  132.  
  133. IsParent:                               ; checks for "." or ".."
  134.     mov    ah, 2Fh                 ; fetch current DTA in ES:BX
  135.     int    21h
  136.         mov     si, bx                  ; point SI to DTA
  137.         add     si, dta_file_offset     ; point SI to dirname within DTA
  138.         lodsb                           ; fetch first char of dirname
  139.         clc
  140.         cmp     al, '.'                 ; check if parent directory
  141.         jne     ip_1                    ;  yep, this is a legit directory
  142.         stc                             ;  nope, set CY to inform calling
  143. ip_1:   retn                            ;  routine
  144.  
  145. NextDir:                                ; finds next subdir in current level
  146.         call    FindDir                 ; select directory DTA
  147.         mov     cx, 10h                 ; directory attribute to look for
  148.         call    FindNext                ; go a'lookin
  149.         retn
  150.  
  151. FindDir:                                ; sets DTA to current directory DTA
  152.         mov     dx, offset dta_buff     ; returns with carry set upon failure
  153.         xor     cx ,cx
  154.         mov     cl, dta_ptr             ; get current dir level, test for
  155.         cmp     cx, 0                   ;  bottom
  156.         je fd_1                         ; 
  157. fd_2:   add     dx, dta_len             ; if not, increment DX to proper level
  158.         loop    fd_2
  159. fd_1:   mov     ah, 1Ah                 ; set DTA
  160.         int     21h
  161.         retn
  162.  
  163. FindFile:                               ; sets DTA to file DTA
  164.         mov     dx, offset std_dta      ; point to file DTA
  165.         mov     ah, 1Ah
  166.         int     21h                     ; set it
  167.  
  168.         call    MakePath                ; construct current path
  169.         mov     si, offset filename     ; add the filespec
  170.         call    File2Path
  171.         xor     cx, cx                  ; set attribute for normal files
  172. ff_1:   retn
  173.  
  174. UpDir:
  175.         inc     dta_ptr                 ; inc the nest and segment pointers
  176.         inc     dir_nest
  177. retn
  178.  
  179. DownDir:                                ; clears last DTA for reuse
  180.         mov     di, offset dta_buff + dta_file_offset   ; point DI to last 
  181.         xor     cx, cx                  ; dirname searched by multiplying 
  182.         mov     cl, dta_ptr             ; length of DTA times No of DTA's 
  183.